﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Modules.franchise.display {
    import flash.events.*;
    import Engine.Managers.*;
    import flash.display.*;
    import org.aswing.*;
    import Classes.*;
    import org.aswing.geom.*;
    import Display.*;
    import flash.text.*;
    import org.aswing.border.*;
    import Modules.franchise.data.*;
    import Display.aswingui.*;
    import L10n.*;

    public class FranchiseTab extends DataItemCell {

        private const TAB_CELL_WIDTH:int = 101;

        protected var m_setIconLoader:Loader = null;
        protected var m_content:DisplayObject;
        protected var m_itemIconPane:JPanel;
        private var m_cellPanel:JPanel;
        private var m_iconPanel:JPanel;
        private var m_itemIconHolder:JPanel;
        private var m_itemBgHolder:JPanel;
        private var m_selected:Boolean = false;
        private var m_bubblePanel:JPanel;
        private var m_bgNorm:DisplayObject;
        private var m_bgOver:DisplayObject;
        private var m_iconBgDec:MarginBackground;
        private var m_selectedFranchise:OwnedFranchiseData;

        public function FranchiseTab(_arg1:LayoutManager=null){
            super(new SoftBoxLayout(SoftBoxLayout.X_AXIS, 0, SoftBoxLayout.LEFT));
        }
        override public function setCellValue(_arg1):void{
            this.setFranchiseCellValue(_arg1);
        }
        private function setFranchiseCellValue(_arg1:OwnedFranchiseData):void{
            this.m_selectedFranchise = _arg1;
            var _local2:String = Global.gameSettings.getImageByName(this.m_selectedFranchise.franchiseType, "icon");
            if (_local2){
                m_loader = LoadingManager.load(_local2, onIconLoad, LoadingManager.PRIORITY_HIGH);
            };
            this.buildCell();
        }
        protected function buildCell():void{
            this.m_cellPanel = ASwingHelper.makeSoftBoxJPanelVertical(SoftBoxLayout.CENTER);
            if (this.franchiseType == "bus_dummy"){
                this.buildNewFranchiseCell();
            } else {
                this.buildExistingFranchiseCell();
            };
            this.append(this.m_cellPanel);
            ASwingHelper.prepare(this);
        }
        override protected function initializeCell():void{
            if (this.franchiseType == "bus_dummy"){
                return;
            };
            var _local1:JPanel = ASwingHelper.makeSoftBoxJPanelVertical(SoftBoxLayout.BOTTOM);
            var _local2:AssetPane = new AssetPane(m_itemIcon);
            this.m_itemIconHolder.setBorder(new EmptyBorder(null, new Insets(15, 0, 0, 0)));
            _local1.append(_local2);
            this.m_itemIconPane.append(_local1);
        }
        protected function onTabOver(_arg1:MouseEvent):void{
            var _local2:MarginBackground = new MarginBackground(this.m_bgOver, new Insets(0, 0, 0, 0));
            this.m_cellPanel.setBackgroundDecorator(_local2);
            ASwingHelper.prepare(this.m_cellPanel);
        }
        protected function onTabOut(_arg1:MouseEvent):void{
            var _local2:MarginBackground = new MarginBackground(this.m_bgNorm, new Insets(0, 0, 0, 0));
            this.m_cellPanel.setBackgroundDecorator(_local2);
            ASwingHelper.prepare(this.m_cellPanel);
        }
        protected function onTabClick(_arg1:MouseEvent):void{
            this.m_selected = true;
            FranchiseMenu.menuUI.switchBusiness(this.m_selectedFranchise.franchiseType);
            this.onTabOver(_arg1);
        }
        private function buildExistingFranchiseCell():void{
            this.buildBackground("fr_tab_normal_new", "fr_tab_selected_new");
            var _local1:JLabel = new JLabel(Global.franchiseManager.model.getFranchiseName(this.m_selectedFranchise.franchiseType));
            _local1.setForeground(new ASColor(FranchiseMenu.COLOR_MENU_STANDARD));
            _local1.setFont(ASwingHelper.getBoldFont(12));
            var _local2:String = Global.franchiseManager.model.getFranchiseName(this.m_selectedFranchise.franchiseType);
            _local2 = LocaleHelper.localSetting.bypassCharactersToNum(_local2, 6);
            var _local3:JTextField = ASwingHelper.makeTextField(_local2, EmbeddedArt.SYSTEM_FONT, 15, FranchiseMenu.COLOR_MENU_STANDARD);
            LocaleHelper.localSetting.TextField_adjust(_local3.getTextField(), {
                embedFonts:false,
                font:EmbeddedArt.SYSTEM_FONT,
                align:"center"
            });
            this.m_itemIconHolder = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.CENTER);
            this.m_itemIconPane = ASwingHelper.makeSoftBoxJPanelVertical(SoftBoxLayout.TOP);
            this.m_itemIconHolder.append(this.m_itemIconPane);
            this.m_itemBgHolder = ASwingHelper.makeSoftBoxJPanelVertical(SoftBoxLayout.BOTTOM);
            this.m_itemBgHolder.setMinimumSize(new IntDimension(this.m_cellPanel.width, (this.m_cellPanel.height - 37)));
            this.m_itemBgHolder.setPreferredSize(new IntDimension(this.m_cellPanel.width, (this.m_cellPanel.height - 37)));
            this.m_itemBgHolder.setMaximumSize(new IntDimension(this.m_cellPanel.width, (this.m_cellPanel.height - 37)));
            this.m_itemBgHolder.append(this.m_itemIconHolder);
            this.m_cellPanel.append(this.m_itemBgHolder);
            this.m_cellPanel.append(_local3);
            this.m_cellPanel.addEventListener(MouseEvent.CLICK, this.onTabClick, false, 0, true);
        }
        private function buildNewFranchiseCell():void{
            var _local1:String;
            var _local2:String;
            this.buildBackground("fr_tab_normalNewFranchise_new", "fr_tab_normalNewFranchise_new");
            if (Global.franchiseManager.isFranchiseLocked()){
                _local1 = ZLoc.t("Main", "franchiseUI_tab_nextFranchiseLocked_header");
                _local2 = ZLoc.t("Main", "franchiseUI_tab_nextFranchiseLocked_footer", {level:Global.franchiseManager.nextFranchiseUnlock.toString()});
            } else {
                _local1 = ZLoc.t("Main", "franchiseUI_tab_nextFranchiseUnlocked_header");
                _local2 = ZLoc.t("Main", "franchiseUI_tab_nextFranchiseUnlocked_footer");
            };
            var _local3:AssetPane = ASwingHelper.makeMultilineCapsText(_local1, this.m_cellPanel.width, EmbeddedArt.DEFAULT_FONT_NAME_BOLD, TextFormatAlign.CENTER, 13, EmbeddedArt.blueTextColor);
            var _local4:AssetPane = ASwingHelper.makeMultilineCapsText(_local2, this.m_cellPanel.width, EmbeddedArt.TITLE_FONT, TextFormatAlign.CENTER, 14, EmbeddedArt.orangeTextColor);
            ASwingHelper.prepare(_local3, _local4);
            var _local5:Number = ((this.m_content.height - 25) - ((_local3.height + _local4.height) + 10));
            this.m_cellPanel.append(ASwingHelper.verticalStrut((_local5 / 2)));
            this.m_cellPanel.append(_local3);
            this.m_cellPanel.append(ASwingHelper.verticalStrut(10));
            this.m_cellPanel.append(_local4);
            this.m_cellPanel.append(ASwingHelper.verticalStrut((_local5 / 2)));
            ASwingHelper.prepare(this.m_cellPanel);
        }
        private function buildBackground(_arg1:String, _arg2:String):void{
            var _local3:DisplayObject = (new (FranchiseMenuUI.m_assetDict[_arg1])() as DisplayObject);
            var _local4:DisplayObject = (new (FranchiseMenuUI.m_assetDict[_arg2])() as DisplayObject);
            this.m_content = _local3;
            this.m_bgNorm = _local3;
            this.m_bgOver = _local4;
            this.setPreferredWidth(this.TAB_CELL_WIDTH);
            this.setMinimumWidth(this.TAB_CELL_WIDTH);
            this.setMaximumWidth(this.TAB_CELL_WIDTH);
            var _local5:MarginBackground = new MarginBackground(this.m_content, new Insets(0, 0, 0, 0));
            this.m_cellPanel.setBackgroundDecorator(_local5);
            this.m_cellPanel.setPreferredSize(new IntDimension(this.TAB_CELL_WIDTH, this.m_content.height));
            this.m_cellPanel.setMinimumSize(new IntDimension(this.TAB_CELL_WIDTH, this.m_content.height));
            this.m_cellPanel.setMaximumSize(new IntDimension(this.TAB_CELL_WIDTH, this.m_content.height));
            ASwingHelper.prepare(this.m_cellPanel);
        }
        public function get franchiseType():String{
            return (this.m_selectedFranchise.franchiseType);
        }
        public function set selectionStatus(_arg1:Boolean):void{
            if (_arg1){
                this.onTabOver(null);
            } else {
                this.onTabOut(null);
            };
        }

    }
}//package Modules.franchise.display 
